<?php
namespace app\Controllers;
use app\Models\UserModel as User;

class UserController {

	//抽取UserModel对象父类
	protected $model;

	public function __construct() {
		$this -> model = new User();
	}

	//查询用户控制器
	public function searchUser() {
		$result = $this -> model -> searchUserModel();
		echo json_encode($result);
	}

	//删除用户控制器
	public function deleteUser($request, $response) {
		$id = $request -> getParam("id");
		$result = $this -> model -> deleteUserModel($id);
		echo json_encode($result);
	}

	//修改用户控制器
	public function modifyUser($request, $response) {
		$userid = $request -> getParam("userid");
		$username = $request -> getParam("username");
		$fullname = $request -> getParam("fullname");
		$user = Array();
		$user["userid"] = $userid;
		$user["username"] = $username;
		$user["fullname"] = $fullname;
		$result = $this -> model -> modifyUserModel($user);
		echo json_encode($result);
	}

	//增加用户控制器
	public function insertUser($request, $response) {
		$username = $request -> getParam("username");
		$fullname = $request -> getParam("fullname");
		$user = Array();
		$user["username"] = $username;
		$user["fullname"] = $fullname;
		$result = $this -> model -> insertUserModel($user);
		echo json_encode($result);
	}

}
?>